package com.elinshaw.pattern.readwritelock;

import lombok.Data;

@Data
public class ReadWriteLockImpl implements ReadWriteLock {

    /**
     * 锁对象
     */
    private Object MUTEX = new Object();

    private int writingWriters = 0;

    private int waitingWriters = 0;

    private int readingReaders = 0;

    /**
     * read和write偏好设置
     */
    private boolean preferWriter;

    public ReadWriteLockImpl() {
        this(true);
    }

    public ReadWriteLockImpl(boolean preferWriter) {
        this.preferWriter = preferWriter;
    }

    @Override
    public Lock readLock() {
        return new ReadLock(this);
    }

    @Override
    public Lock writeLock() {
        return new WriteLock(this);
    }

    @Override
    public int getWritingWriters() {
        return 0;
    }

    @Override
    public int getWaitingWriters() {
        return 0;
    }

    @Override
    public int getReadingReaders() {
        return 0;
    }

}
